﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;
using System.IO;

namespace Guarouba.Classes
{
    public class Tabelas
    {
        private static string GerarTabela(string cabecalho, string registros)
        {
            StringBuilder sbTable = new StringBuilder();

            sbTable.AppendLine(@"<div style=""border:1px solid #CCC; padding:20px;"">");
            sbTable.AppendLine(@"<table id=""tableDefaultGRB"" class=""table table-striped"">");
            sbTable.AppendLine(@"<thead>");
            sbTable.AppendLine(@"<tr style=""background-color:#005ACC; color:#FFF;"">");
            
            //Cabeçalho da Tabela
            sbTable.AppendLine(cabecalho);
            sbTable.AppendLine(@"</tr>");
            sbTable.AppendLine(@"</thead>");
            sbTable.AppendLine(@"<tbody>");
            
            //Registros da tabela
            sbTable.AppendLine(registros);
            
            sbTable.AppendLine(@"</tbody>");
            sbTable.AppendLine(@"</table>");
            sbTable.AppendLine(@"</div>");

            return sbTable.ToString();
        }

        public static string TabelaUsuariosDoSistema()
        {
            DataTable dt = new DataTable();
            BLL.Seguranca seg = new BLL.Seguranca();
            string tabela = string.Empty;

            StringBuilder sbCabecalho = new StringBuilder();
            StringBuilder sbRegistros = new StringBuilder();

            dt = seg.ListaUsuarios();
            if (dt != null)
            {
                sbCabecalho.AppendLine("<th>Nome do Usuário</th>");
                sbCabecalho.AppendLine("<th>E-mail</th>");
                sbCabecalho.AppendLine("<th>Login do Usuário</th>");
                sbCabecalho.AppendLine("<th></th>");

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string idRegistro =  dt.Rows[i]["IDLogin"].ToString();
                    idRegistro = Classes.Tools.Encript(idRegistro);

                    string editButton = String.Format(@"<a href=""002-Usuarios-Detalhes.aspx?ID={0}"" class=""btn btn-mini btn-primary"" >Detalhes</a>", idRegistro);

                    sbRegistros.AppendLine(@"<tr>");
                    sbRegistros.AppendLine(String.Format("<td>{0}</td>", dt.Rows[i]["Nome"].ToString()));
                    sbRegistros.AppendLine(String.Format("<td>{0}</td>", dt.Rows[i]["Email"].ToString()));
                    sbRegistros.AppendLine(String.Format("<td>{0}</td>", dt.Rows[i]["NomeUsuario"].ToString()));
                    sbRegistros.AppendLine(String.Format(@"<td class=""RightButtonList"">{0}</td>", editButton));
                    sbRegistros.AppendLine(@"</tr>");
                }

                tabela = GerarTabela(sbCabecalho.ToString(), sbRegistros.ToString());
            }

            return tabela;
        }

        public static string TabelaFormacoesAcademicas()
        {
            DataTable dt = new DataTable();
            BLL.FormacaoAcademica fac = new BLL.FormacaoAcademica();
            string tabela = string.Empty;

            StringBuilder sbCabecalho = new StringBuilder();
            StringBuilder sbRegistros = new StringBuilder();

            dt = fac.ListaFormacoes();
            if (dt != null)
            {
                sbCabecalho.AppendLine("<th>Formação Acadêmica</th>");
                sbCabecalho.AppendLine("<th></th>");

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string idRegistro = dt.Rows[i]["IDFormacao"].ToString();
                    idRegistro = Classes.Tools.Encript(idRegistro);                    

                    string editButton = String.Format(@"<a href=""004-FormacoesAcademicas-Detalhes.aspx?ID={0}"" class=""btn btn-mini btn-primary"" >Detalhes</a>", idRegistro);

                    sbRegistros.AppendLine(@"<tr>");
                    sbRegistros.AppendLine(String.Format("<td>{0}</td>", dt.Rows[i]["Formacao"].ToString()));
                    sbRegistros.AppendLine(String.Format(@"<td class=""RightButtonList"">{0}</td>", editButton));
                    sbRegistros.AppendLine(@"</tr>");
                }

                tabela = GerarTabela(sbCabecalho.ToString(), sbRegistros.ToString());
            }

            return tabela;
        }

        public static string TabelaVagas()
        {
            DataTable dt = new DataTable();
            BLL.Vagas vag = new BLL.Vagas();
            string tabela = string.Empty;

            StringBuilder sbCabecalho = new StringBuilder();
            StringBuilder sbRegistros = new StringBuilder();

            dt = vag.ListaVagas();
            if (dt != null)
            {
                sbCabecalho.AppendLine("<th>Título da Vaga</th>");
                sbCabecalho.AppendLine("<th>N.º Vagas</th>");
                sbCabecalho.AppendLine("<th>Localidade</th>");
                sbCabecalho.AppendLine("<th>Status</th>");
                sbCabecalho.AppendLine("<th></th>");

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string idRegistro = dt.Rows[i]["IDVaga"].ToString();
                    idRegistro = Classes.Tools.Encript(idRegistro);

                    string editButton = String.Format(@"<a href=""006-Vagas-Detalhes.aspx?ID={0}"" class=""btn btn-mini btn-primary"" >Detalhes</a>", idRegistro);

                    sbRegistros.AppendLine(@"<tr>");
                    sbRegistros.AppendLine(String.Format("<td>{0}</td>", dt.Rows[i]["TituloVaga"].ToString()));
                    sbRegistros.AppendLine(String.Format("<td>{0}</td>", dt.Rows[i]["NumeroVagas"].ToString()));
                    sbRegistros.AppendLine(String.Format("<td>{0}</td>", dt.Rows[i]["Localidade"].ToString()));
                    sbRegistros.AppendLine(String.Format("<td>{0}</td>", dt.Rows[i]["Status"].ToString()));
                    sbRegistros.AppendLine(String.Format(@"<td class=""RightButtonList"">{0}</td>", editButton));
                    sbRegistros.AppendLine(@"</tr>");
                }

                tabela = GerarTabela(sbCabecalho.ToString(), sbRegistros.ToString());
            }

            return tabela;
        }
    }
}